// 服务方法类型映射（确保方法存在性）
type ServiceMethodMap = {
  [ServiceType.BizService]: keyof IBizService
  [ServiceType.StructureService]: keyof IStructureService
  [ServiceType.BQItemService]: keyof IBQItemService
  [ServiceType.LmmDetailService]: keyof ILmmDetailService
}

// 类型安全的命令工厂
class CommandFactory {
  static create<M extends ServiceMethodMap[S], S extends ServiceType>(
    service: S,
    method: M,
    ...params: Parameters<InstanceType<ServiceInterfaceMap[S]>[M]>
  ): ICommand {
    return {
      service,
      method,
      params,
      execute: async () => {
        const serviceInstance = ServiceRegistry.getInstance().resolve(service)
        return serviceInstance[method](...params)
      },
    }
  }
}

// 使用示例
const cmd = CommandFactory.create(
  ServiceType.BQItemService,
  'updateItemPrice', // 自动检查方法是否存在
  'item-123', // 自动检查参数类型
  99.99,
)
